<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/normalize.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
</head>

<body>
<form class="page-search layui-form" lay-filter="search-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">患者编号</label>
            <div class="layui-input-inline">
                <input name="search-key" placeholder="请输入输入患者编号" class="search-key layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="search-submit">查询</button>
            <button id="create-btn" class="layui-btn">新增</button>
        </div>
    </div>
</form>
<table class="layui-hide" id="table" lay-filter="table"></table>
<div class="color-remark"></div>
<div id="pagination"></div>


<script type="text/html" id="tableBar">
    <button class="layui-btn layui-btn-xs" lay-event="check">病历</button>
</script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    var init;
    layui.use(['table', 'form', 'laypage', 'conf', 'utils', 'filters', 'dateFilters', 'consultationServices','widget'], function (table, form, laypage, config, utils, filters, dateFilters, consultationServices, widget) {
        var $createBtn = $('#create-btn');

        /**
         * @author: ares
         * @date: 2021/3/25 9:25
         * @description: 初始化
         */
        init = function () {
            getPageList(1, config.pagination.limit);
            renderPatientClassifyColorMark();
        }
        init();

        utils.aresPageEventInit('updateConsultationList', 'consultation', function () {
            getPageList(1, config.pagination.limit);
        })

        /**
         * @author: ares
         * @date: 2021/1/25 9:16
         * @description: 查询
         */
        form.on('submit(search-submit)', function (data) {
            getPageList(1, config.pagination.limit);
            return false;
        });

        /**
         * @author: ares
         * @date: 2021/3/25 9:42
         * @description: 新增
         */
        $createBtn.on('click', function (event) {
            utils.layerOpen({
                type: 2,
                title: '新增会诊',
                area: ['800px', '500px'],
                content: 'pages/consultation/form.html',
                end: function (index, layero) {

                }
            });
        })

        /**
         * @author: ares
         * @date: 2021/3/25 9:25
         * @description: 分页查询
         * @param {number}currentPage
         * @param {number}pageSize
         */
        function getPageList(currentPage, pageSize) {
            var $searchKey = $(".search-key");
            consultationServices.getConsultationPageListService(currentPage, pageSize, {search_key: $searchKey.val()}).then(function (res) {
                var data = res.data,
                    list = data.list || [];
                utils.laypageRender(laypage, $.extend(config.pagination, {count: data.count, curr: data.current_page}), function (obj) {
                    getPageList(obj.curr, obj.limit);
                });
                table.render({
                    elem: '#table',
                    data: list,
                    cellMinWidth: 50,
                    cols: [[
                        {
                            title: '类型', width: 50, align: 'center',
                            templet: function (d) {
                                return '<i class="fa-circle" style="color: ' + filters.patientClassifyColorFormat(d.classify) + ';"></i>';
                            }
                        },
                        {title: '患者编号', templet: '<span>{{d.number}}</span>'},
                        {title: '姓名', width: 70, templet: '<span>{{d.patientName}}</span>'},
                        {
                            title: '性别',
                            width: 70,
                            templet: function (d) {
                                return filters.sexFormat(d.sex);
                            }
                        },
                        {
                            title: '年龄',
                            width: 70,
                            templet: function (d) {
                                return filters.ageFormat(d.birthday);
                            }
                        },
                        {
                            title: '医保类型',
                            width: 80,
                            templet: function (d) {
                                return filters.insuranceTypeFormat(d.insuranceType);
                            }
                        },
                        {
                            title: '床旁治疗',
                            width: 80,
                            templet: function (d) {
                                return d.besidePatient ? '是' : '否';
                            }
                        },
                        {title: '病区/病床', templet: '<span>{{d.wardBedNumber}}</span>'},
                        {title: '主诉', templet: '<span>{{d.mainNarrate}}</span>'},
                        {title: '创建时间', width: 130, templet: '<span>{{d.createTime}}</span>'},
                        {title: '操作', fixed: 'right', width: 80, templet: '#tableBar'}
                    ]]
                });
                table.on('tool(table)', function (obj) {
                    var data = obj.data;
                    switch (obj.event) {
                        case 'check':
                            checkInfo(data);
                            break;
                    }
                    ;
                })
            });

        }

        /**
         * @author: ares
         * @date: 2021/3/25 14:30
         * @description: 查看病历
         * @param {object}data 当前行数据
         */
        function checkInfo(data) {
            var query = {
                dis_edit: true,
                mes_emr: true,
                type: 1
            };
            utils.pushTopRoute('/emr/info/' + data.id, query);
        }

        /**
         * @author: ares
         * @date: 2021/3/26 11:27
         * @description: 渲染病患类型颜色标记
         */
        function renderPatientClassifyColorMark() {
            $('.color-remark').empty().append(widget.createPatientClassifyColorMark());
        }
    })
</script>


</body>

</html>
